const fs = require('fs');
const md5 = require("md5");

const __dir__ = "F:/BaiduNetdiskDownload/觅/觅长生/";
const __dir2_ = "/觅长生_Data/Res/Effect/json/";

const pathc = {
    juese: `${__dir__}MCSSave/Avatar2/Slot1/Avatar.json`,
    shentong: `${__dir__}${__dir2_}d_skills.py.datas.json`,
    gongfa: `${__dir__}${__dir2_}d_staticSkill.py.datas.json`,
    wupin: `${__dir__}${__dir2_}d_items.py.datas.json`
}

// 接口输出json对象转字符串
function httpWriteParse(data) {
    return `{"data":${JSON.stringify(data)},"status":"200"}`
}

// 读取
function read(path) {
    return fs.readFileSync(path, "utf-8");
}

// 写入
function write(path, data) {
    return fs.writeFileSync(path, data);
}


async function learnShenTong(params) {
    let obj = JSON.parse(read(pathc.juese));
    obj.hasSkillList.push({
        UUID: md5(new Date().getTime()),
        id: params,
        level: params.lv || 5,
        index: 0,
        Seid: {}
    })
    // console.log(params)
    write(pathc.juese, JSON.stringify(obj, null, '\t'))
    return true;
}

async function learnGongFa(params) {
    let obj = JSON.parse(read(pathc.juese));
    obj.hasStaticSkillList.push({
        UUID: md5(new Date().getTime()),
        id: params,
        level: params.lv || 5,
        index: 0,
        Seid: {}
    })
    // console.log(params)
    write(pathc.juese, JSON.stringify(obj, null, '\t'))
    return true;
}
module.exports = {
    httpWriteParse,
    read,
    learnShenTong,
    learnGongFa,
    pathc
}